@extends('admin.common.admin')

@section('cnt')
    {{-- 面包屑导航 --}}
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i> 接口账号管理
        <span class="c-gray en">&gt;</span> 接口账号列表
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新"><i class="Hui-iconfont">&#xe68f;</i></a>
    </nav>
    <div class="page-container">
        @include('admin.common.msg')

        <div class="text-c">
            <form>
                日期范围：
                <input type="text" value="{{ request()->get('datemin') }}" autocomplete="off" onfocus="WdatePicker({})" name="datemin" class="input-text Wdate" style="width:120px;">
                -
                <input type="text" value="{{ request()->get('datemax') }}" autocomplete="off" onfocus="WdatePicker({})" name="datemax" class="input-text Wdate" style="width:120px;">
                <input type="text" class="input-text" style="width:250px" value="{{ request()->get('username') }}" placeholder="输入账号" name="username">
                <button type="submit" class="btn btn-success radius" id="" name=""><i class="Hui-iconfont">&#xe665;</i> 搜用户</button>
            </form>
        </div>
        <div class="cl pd-5 bg-1 bk-gray mt-20">
            <span class="l">
                {!! $apiuser->addBtn('admin.apiuser.create','添加接口账号') !!}
            </span>
            <span class="r">共有数据：<strong>{{ $data->total() }}</strong> 条</span></div>
        <div class="mt-20">
            <table class="table table-border table-bordered table-hover table-bg table-sort">
                <thead>
                <tr class="text-c">
                    <th width="80">ID</th>
                    <th width="100">账号</th>
                    <th width="100">密码</th>
                    <th width="100">Token</th>
                    <th width="100">状态</th>
                    <th width="100">访问次数/当天</th>
                    <th width="100">操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $item)
                    <tr class="text-c">
                        <td>{{ $item->id }}</td>
                        <td>{{ $item->username }}</td>
                        <td>{{ $item->password }}</td>
                        <td>{{ $item->token }}</td>
                        <td class="td-status">
                            @if(!$item->deleted_at)
                                <span class="label label-success radius">已启用</span>
                            @else
                                <span class="label label-danger radius">禁用</span>
                            @endif
                        </td>
                        <td>{{ $item->click }}</td>
                        <td class="td-manage">
                            {!! $item->editBtn('admin.apiuser.edit','修改',$item) !!}
                            {!! $item->delBtn('admin.apiuser.destroy','删除',$item) !!}
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
        {{ $data->appends(request()->except('page'))->links() }}
    </div>
@endsection

@section('js')
    <script>
        // 删除用户操作
        $('.deleteBtn').click(function () {
            //询问框
            layer.confirm('您真的要删除此记录信息吗？', {
                btn: ['确认删除', '考虑一下']
            }, () => {
                // 发起ajax请求，进行删除操作
                $.ajax({
                    url: $(this).attr('href'),
                    type: 'delete',
                    data: {
                        _token: "{{ csrf_token() }}"
                    }
                }).then(ret => {
                    layer.msg(ret.msg, {icon: 1, time: 2000}, () => {
                        $(this).parents('tr').remove();
                    });
                })
            });
            // 阻止默认行为
            return false;
        });
    </script>

@endsection
